package com.example.springbootdisconf.rest;

import com.alibaba.fastjson.JSON;
import com.example.springbootdisconf.config.RedisConfig;
import com.example.springbootdisconf.config.KeyValueConfig;
import com.example.springbootdisconf.config.SimpleConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/disconf")
public class DisconfRest {
    @Autowired
    KeyValueConfig KeyValueConfig;
    @Autowired
    SimpleConfig simpleConfig;
    @Autowired
    RedisConfig redisConfig;

    /**
     * 配置项测试
     */
    @GetMapping("/keyValue")
    public String testKeyValue() {
        String aa = KeyValueConfig.getAa();
        return aa;
    }

    /**
     * 自动重载模式测试
     */
    @GetMapping("/autoReload")
    public String testAutoReload() {
        return JSON.toJSONString("simpleConfig的name：" + simpleConfig.getName() + "、age：" + simpleConfig.getAge());
    }
    /**
     * 普通托管模式测试
     *
     * @return
     */
    @GetMapping("/trusteeship")
    public String testTrusteeship() {
        return JSON.toJSONString("redis的host：" + redisConfig.getHost() + "、port：" + redisConfig.getPort());
    }
}
